package com.hrt.datasender.datacollect.drive.opc;

import java.util.HashMap;

import com.btcode.common.MyLog;
import com.btcode.log.ILog;
import com.hrt.datasender.datacollect.drive.DriveConfigModel;
import com.hrt.datasender.datacollect.drive.DriveTimer;
import com.hrt.datasender.datadao.model.BcDevicesModel;
import com.hrt.datasender.mq.MqKit;
import com.hrt.datasender.mq.model.OpcModel;

/**
 * Opc数据询问器
 * 
 * @author wencheng
 *
 */
public class OpcDataAsker extends DriveTimer {

    private ILog log = null;

    @Override
    public void executeTimer(DriveConfigModel configs, BcDevicesModel deviceData) {

        try {
            log = MyLog.getInstance().getLogger(getClass().getName() + "." + deviceData.getDeviceName());
            HashMap<String,OpcDataClient> opcDataReaderMap = OpcDrive.opcDataReaderMap;
            OpcDataClient opcDataReader = opcDataReaderMap.get(deviceData.getDeviceName());
            // 读取OPC数据，并插入到MQ队列
            HashMap<String, String> opcData = opcDataReader.getData();
            OpcModel op = new OpcModel(opcData, configs.getName());
            MqKit.productMsgToOpcMQ(op);
            log.info("读取OPC数据成功");
        }
        catch (Exception e) {
            log.error("读取OPC数据出错", e);
        }
    }
}
